package com.boc.langxiang.ui.adapter.me;

import android.content.Context;
import android.widget.ImageView;

import com.boc.langxiang.R;
import com.boc.langxiang.entity.response.LeaveContentList;
import com.boc.langxiang.manager.PicassoImageLoader;
import com.boc.langxiang.util.StringUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import static com.boc.langxiang.R.id.item;

public class LeaveToFlowOutRVAdapter extends BaseQuickAdapter<LeaveContentList> {

    public LeaveToFlowOutRVAdapter(Context context, List<LeaveContentList> data) {
        super(R.layout.item_me_orders_leaveflowout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LeaveContentList item) {
        String content = item.getContent();
        String answer = item.getAnswer();
        boolean answerNull = true;
        if (answer == null) {
            answerNull = true;
        } else {
            answerNull = false;
        }

        String ispicS = item.getIspic();
        boolean ispic = true;
        if ("1".equals(ispicS)) {
            ispic = true;
        } else {
            ispic = false;
        }

        //无回复
        if (answerNull) {
            helper.setVisible(R.id.relayout_me_leave_left, false)
                    .setVisible(R.id.relayout_me_leave_right, true);
            String photourl = item.getPhotourl();
            if (StringUtil.isEmpty(photourl)) {
                PicassoImageLoader.getInstance().displayUrlImage(mContext, null, (ImageView) helper.getView(R.id.riv_me_leave_right));
            } else {
                PicassoImageLoader.getInstance().displayUrlImage(mContext, item.getPhotourl(), (ImageView) helper.getView(R.id.riv_me_leave_right));
            }

            if (ispic) {
                helper.setVisible(R.id.tv_me_leave_right, false)
                        .setVisible(R.id.riv_me_leave_right_img, true);
                if (item.isLocalPic()) {
                    PicassoImageLoader.getInstance().displayFileImage(mContext, content, (ImageView) helper.getView(R.id.riv_me_leave_right_img));
                } else {
                    PicassoImageLoader.getInstance().displayUrlImage(mContext, content, (ImageView) helper.getView(R.id.riv_me_leave_right_img));
                }

            } else {
                helper.setVisible(R.id.tv_me_leave_right, true)
                        .setVisible(R.id.riv_me_leave_right_img, false)
                        .setText(R.id.tv_me_leave_right, StringUtil.isEmpty(content) ? "" : content);
            }
        } else {
            //有回复
            helper.setVisible(R.id.relayout_me_leave_left, true)
                    .setVisible(R.id.relayout_me_leave_right, true);

            String photourl = item.getPhotourl();
            if (StringUtil.isEmpty(photourl)) {
                PicassoImageLoader.getInstance().displayUrlImage(mContext, null, (ImageView) helper.getView(R.id.riv_me_leave_right));
            } else {
                PicassoImageLoader.getInstance().displayUrlImage(mContext, item.getPhotourl(), (ImageView) helper.getView(R.id.riv_me_leave_right));
            }

            if (ispic) {
                helper.setVisible(R.id.tv_me_leave_right, false)
                        .setVisible(R.id.riv_me_leave_right_img, true);
                if (item.isLocalPic()) {
                    PicassoImageLoader.getInstance().displayFileImage(mContext, content, (ImageView) helper.getView(R.id.riv_me_leave_right_img));
                } else {
                    PicassoImageLoader.getInstance().displayUrlImage(mContext, content, (ImageView) helper.getView(R.id.riv_me_leave_right_img));
                }

            } else {
                helper.setVisible(R.id.tv_me_leave_right, true)
                        .setVisible(R.id.riv_me_leave_right_img, false)
                        .setText(R.id.tv_me_leave_right, StringUtil.isEmpty(content) ? "" : content);
            }
            
            PicassoImageLoader.getInstance().displayUrlImage(mContext, item.getLcphotourl(), (ImageView) helper.getView(R.id.riv_me_leave_left));

            //如果是Img
//            if (ispic) {
//                helper.setVisible(R.id.tv_me_leave_left, false)
//                        .setVisible(R.id.riv_me_leave_left_img, true);
//                PicassoImageLoader.getInstance().displayUrlImage(mContext, content, (ImageView) helper.getView(R.id.riv_me_leave_left_img));
//            } else {
                helper.setVisible(R.id.tv_me_leave_left, true)
                        .setVisible(R.id.riv_me_leave_left_img, false)
                        .setText(R.id.tv_me_leave_left, StringUtil.isEmpty(answer) ? "" : answer);
//            }
        }
    }

//    public void setIsLocal(boolean islocal) {
//        this.islocal = islocal;
//    }
}
